package com.gxa.controller.GlmController;

import com.gxa.service.RefundService;
import com.gxa.utils.R;
import com.gxa.vo.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "退款记录模块")
@RestController
public class RefundController {

    @Autowired
    private RefundService refundService;


    //退款记录

    @ApiOperation(value="退款记录渲染接口",notes="用于点击退款记录时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回退款记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/refund/queryRefund")
    public R queryRefund(){

        List<RefundcordVo> refundcordVos = this.refundService.queryAll();

        return R.ok().put("data",refundcordVos);
    }

    @ApiOperation(value="退款记录搜索接口",notes="用于点击搜索退款记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回退款记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/refund/selectRefund")
    public R selectRefund(@ApiParam(name="begintime,endtime,namecard",value = "时间,病人/就诊卡号--用于操作退款记录",required = true)@RequestBody OutexvalueVo outexvalueVo){

        List<RefundcordVo> refundcordVos = this.refundService.selectAll(outexvalueVo.getBegintime(),outexvalueVo.getEndtime(),outexvalueVo.getNamecard());

        return R.ok().put("data",refundcordVos);
    }

    @ApiOperation(value="退款记录操作接口",notes="用于点击操作退款记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回退款记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/refund/orderRefund")
    public R orderRefund(@ApiParam(name="order_num,medcard",value = "订单号,就诊卡号--用于操作退款记录",required = true)@RequestBody DovalueVo dovalueVo){

        List<PatientmsgVo> patientmsgVos = this.refundService.queryAllpmsg(dovalueVo.getMedcard());
        List<OrderfundmsgVo> orderfundmsgVos = this.refundService.queryAllomsg(dovalueVo.getOrder_num());

        Map map = new HashMap();



        map.put("patientmsg",patientmsgVos);
        map.put("ordermsg",orderfundmsgVos);

        return R.ok().put("data",map);
    }

    @ApiOperation(value="退款记录订单备注接口",notes="用于点击保存订单备注",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回退款记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:update")
    @PostMapping("/refund/updateOrderremark")
    public R updateOrderremark(@ApiParam(name="ordernum,remark",value = "订单号,备注信息--用于退款记录的订单备注",required = true)@RequestBody OrderfundmsgVo orderfundmsgVo){

        this.refundService.updateRemark(orderfundmsgVo.getOrder_num(),orderfundmsgVo.getRemark());
        List<OrderfundmsgVo> orderfundmsgVos = this.refundService.queryAllomsg(orderfundmsgVo.getOrder_num());

        return R.ok().put("data",orderfundmsgVos);
    }
}
